﻿using UnityEngine;
using UnityEngine.UI;

namespace UnityView
{
    class ImageTextView : UIView
    {
        
        public static ColorBlock AppearanceColorBlock = ColorBlock.defaultColorBlock;

        private UnityEngine.UI.Text _textComponent;
        public UnityEngine.UI.Text TextComponent
        {
            set
            {
                _textComponent = value;
            }
            get
            {
                if (_textComponent != null) return _textComponent;
                var text = UnityView.TextView.BaseTextView();
                _textComponent = text.GetComponent<UnityEngine.UI.Text>();
                text.transform.SetParent(RectTransform);
                RectFill(text.GetComponent<RectTransform>());
                return _textComponent;
            }
        }
        public TextAnchor Alignment
        {
            set
            {
                TextComponent.alignment = value;
            }
            get
            {
                return TextComponent.alignment;
            }
        }

        public string Text
        {
            set
            {
                TextComponent.text = value;
            }
            get
            {
                return TextComponent.text;
            }
        }
        [Animatable]
        public Color TextColor
        {
            set
            {
                if (UIAnimation.OnAnimate())
                {
                    UIAnimation.Append(new TextColorAction(TextComponent, TextComponent.color, value));
                }
                else
                {
                    TextComponent.color = value;
                }
            }
            get
            {
                return TextComponent.color;
            }
        }

        public int FontSize
        {
            set
            {
                TextComponent.fontSize = value;
            }
            get
            {
                return FontSize;
            }
        }

        public ImageTextView()
            : this(UICanvas.GetInstance()) { }

        public ImageTextView(RectTransform transform) : base(transform)
        {

        }

        public ImageTextView(IViewLayout viewView)
            : base(viewView)
        {
        }

        public ImageTextView(GameObject gameObject)
            : base(gameObject)
        {
        }
    }
}
